//
//  Person.m
//  Oc02_实例变量可见度_方法
//
//  Created by dllo on 16/2/25.
//  Copyright © 2016年 Apon. All rights reserved.
//

#import "Person.h"

@implementation Person
#pragma mark - 重写init
-(instancetype)init{
    //调用父类的init方法, self指的是对象本身
    self = [super init];
    //加一个判断条件, 当self指针不为空时,在进行赋值.
    if (self) {
        //给某些实例变量赋初值.
        _age = 20;
    }
    
    
    return self;
}


#pragma mark - other
/** 需求: 通过一个方法, 把三个实例变量赋值. */
- (void)Name:(NSString *)name Sex:(NSString *)sex Age:(NSInteger)age {
    _name = name;
    _sex = sex;
    _age = age;
}
- (void)sayHi{

    NSLog(@"name:%@, sex:%@, age:%ld", _name, _sex, _age);
}
#pragma mark - setter getter
/** 需求: 通过一个方法, 对_name实例变量赋值. */
- (void)setName:(NSString *)name{

    _name = name;
}
- (NSString *)name{
    return _name;
}


#pragma mark - 自定义初始化方法
- (instancetype)initWithName:(NSString *)name{

    self = [super init];
    if (self) {
        //实例变量赋值
        _name = name;
    }
    return self;
} 

-(instancetype)initWithName:(NSString *)name sex:(NSString *)sex age:(NSInteger)age{
    self = [super init];
    if (self) {
        _name = name;
        _age = age;
        _sex = sex;
    }
    return self;
}
#pragma mark - 构造器
+ (instancetype)person{
    //1.alloc
    Person *per = [[Person alloc] init];
    //返回对象
    return per;
}
+(instancetype)personWithName:(NSString *)name sex:(NSString *)sex age:(NSInteger)age{
    Person *per2 = [[Person alloc] initWithName:name sex:sex age:age];
//    per2->_name = name;
//    per2->_age = age;
//    per2->_sex = sex;
    
    
    return per2;
    
}




















@end
